import { defineConfig } from 'astro/config';
import solidJs from "@astrojs/solid-js";
import UnoCSS from 'unocss/astro'

import playformCompress from "@playform/compress";
import playformInline from "@playform/inline";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const mobile = !!/android|ios/.exec(process.env.TAURI_ENV_PLATFORM);

const host = process.env.TAURI_DEV_HOST;

let hmrPort = 5183;

// https://astro.build/config
export default defineConfig({
  resolve: {
    alias: {
      "@": resolve(__dirname, "./src"),
      "~": resolve(__dirname, "./src"),
    }
  },
  integrations: [UnoCSS(), solidJs(), playformInline(), playformCompress()],
  server: {
    host: mobile ? "0.0.0.0" : false, // listen on all addresses
    port: 1420,
    strictPort: true,
    hmr: mobile
      ? {
        protocol: "ws",
        host,
        port: hmrPort++,
      }
      : undefined,
    watch: {
      // 2. tell vite to ignore watching `src-tauri`
      ignored: ["**/src-tauri/**"],
    },
  },
  resolveEnvPrefix: ["VITE_", "TAURI_"],
});
